#include "auth.h"

#include <core/Events.h>
#include <core/ImageMgr.h>

#include <QApplication>
#include <functional>

#include "MessageProcess.h"
#include "ui/StartupDlg.h"
#include "ui/StatusBar.h"

IDictUpdate* auth_dict_updater = nullptr;
bool authlogin(IDictUpdate* p) {
  auth::InitDecodeFuncs();
  ImgMgr::instance().registerImgs("auth");
  auth_dict_updater = p;
  StartupDlg loginDlg;
  int ret = loginDlg.exec();
  if (ret == QDialog::Accepted) {
    auto* worker = new StatusBarWorker();
    widgetEventDispatcher.appendListener(
        EVENT_FRAME_READY,
        std::bind(&StatusBarWorker::onReady, worker, std::placeholders::_1));
    normalNoArgEventDispatcher.appendListener(
        EVENT_USERINFO_READY,
        std::bind(&StatusBarWorker::onUserInfoReady, worker));
    normalNoArgEventDispatcher.appendListener(
        EVENT_MAINWINDOW_MOVE,
        std::bind(&StatusBarWorker::moveBtnTips, worker));
  }
  return (ret == QDialog::Accepted);
}
